<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Generate a keyed hash value using the HMAC method</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.hash-hmac-file.html">hash_hmac_file</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.hash-init.html">hash_init</a></div>
 <div class="up"><a href="ref.hash.html">Hash 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.hash-hmac" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">hash_hmac</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.2, PECL hash &gt;= 1.1)</p><p class="refpurpose"><span class="refname">hash_hmac</span> &mdash; <span class="dc-title">Generate a keyed hash value using the HMAC method</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.hash-hmac-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">string</span> <span class="methodname"><strong>hash_hmac</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$algo</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$data</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$key</code></span>
   [, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$raw_output</code><span class="initializer"> = false</span></span>
  ] )</div>


 </div>

 <div class="refsect1 parameters" id="refsect1-function.hash-hmac-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">algo</code></em></dt>

     <dd>

      <p class="para">
       Name of selected hashing algorithm (i.e. &quot;md5&quot;, &quot;sha256&quot;, &quot;haval160,4&quot;, etc..) See <span class="function"><a href="function.hash-algos.html" class="function">hash_algos()</a></span> for a list of supported algorithms.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">data</code></em></dt>

     <dd>

      <p class="para">
       Message to be hashed.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">key</code></em></dt>

     <dd>

      <p class="para">
       Shared secret key used for generating the HMAC variant of the message digest.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">raw_output</code></em></dt>

     <dd>

      <p class="para">
       When set to <strong><code>TRUE</code></strong>, outputs raw binary data.
       <strong><code>FALSE</code></strong> outputs lowercase hexits.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.hash-hmac-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns a string containing the calculated message digest as lowercase hexits
   unless <em><code class="parameter">raw_output</code></em> is set to true in which case the raw
   binary representation of the message digest is returned.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.hash-hmac-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-807">
    <p><strong>Example #1 <span class="function"><strong>hash_hmac()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">hash_hmac</span><span style="color: #007700">(</span><span style="color: #DD0000">'ripemd160'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'The&nbsp;quick&nbsp;brown&nbsp;fox&nbsp;jumped&nbsp;over&nbsp;the&nbsp;lazy&nbsp;dog.'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'secret'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
b8e7ae12510bdfb1812e463a7f086122cf37e4f7
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.hash-hmac-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.hash.html" class="function" rel="rdfs-seeAlso">hash()</a> - Generate a hash value (message digest)</span></li>
    <li class="member"><span class="function"><a href="function.hash-algos.html" class="function" rel="rdfs-seeAlso">hash_algos()</a> - Return a list of registered hashing algorithms</span></li>
    <li class="member"><span class="function"><a href="function.hash-init.html" class="function" rel="rdfs-seeAlso">hash_init()</a> - Initialize an incremental hashing context</span></li>
    <li class="member"><span class="function"><a href="function.hash-hmac-file.html" class="function" rel="rdfs-seeAlso">hash_hmac_file()</a> - Generate a keyed hash value using the HMAC method and the contents of a given file</span></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.hash-hmac-file.html">hash_hmac_file</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.hash-init.html">hash_init</a></div>
 <div class="up"><a href="ref.hash.html">Hash 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
